package io.renren.modules.sys.controller;

import io.renren.common.utils.R;
import io.renren.modules.sys.entity.CarType;
import io.renren.modules.sys.entity.dto.CarTypeSaveDto;
import io.renren.modules.sys.service.CarTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@Slf4j
    @RequestMapping("/CarType")
public class CarTypeController {
    @Autowired
    private CarTypeService carTypeService;
    @RequestMapping("/selAllType")
    public R selAllType(){
        List<CarType> carTypeList = carTypeService.selAllType();
        return R.ok().put("carTypeList",carTypeList);
    }
    @RequestMapping("/save")
    public R save(@RequestBody CarTypeSaveDto carTypeSaveDto){
        CarType carType = new CarType();
        BeanUtils.copyProperties(carTypeSaveDto,carType);
        carType.setCreateTime(new Date());
        carType.setUpdataTime(new Date());
        carTypeService.save(carType);
        return R.ok();
    }
    @RequestMapping("/delete")
    public R delete(@RequestBody Long id){
        carTypeService.delete(id);
        return R.ok();
    }
    @RequestMapping("/update")
    public R update(@RequestBody CarTypeSaveDto carTypeSaveDto){
        CarType carType = new CarType();
        BeanUtils.copyProperties(carTypeSaveDto,carType);
        carType.setCreateTime(new Date());
        carType.setUpdataTime(new Date());
        carTypeService.update(carType);
        return R.ok();
    }
}
